from ..Util.NetUtil import sendAppMsg
from ..Shell import shell, Shell
# _app = Shell(root=True)


def startApp():
    pass


def startPackage(package):
    _data = {
        'packageName': package,
    }
    sendAppMsg(11, _data)


def startActivity(activity):
    sendAppMsg(12, activity)


def launchApp(appName):
    launch(getPackageName(appName))


def launch(packageName):
    launchPackage(packageName)


def launchPackage(packageName):
    _app.exec('monkey', '-p', packageName, '-c', 'android.intent.category.LAUNCHER', 1)


def killPackage(packageName):
    _app.exec('am','force-stop',packageName)


def killApp(appName):
    killPackage(getPackageName(appName))


def getAppName():
    _app.exec('pm ')


def getPackageName():
    return ''

#cannot
def getAllPackages():
    # _app.exec('pm list packages')
    # return _app.getResultAndClose()
    return shell('ls -hla', root=True)


def installApp(filePath):
    _app.exec('pm install', filePath)


def uninstallApp(appName):
    _app.exec('pm uninstall', getPackageName(appName))


def uninstallPackage(packageName):
    _app.exec('pm uninstall', packageName)
